package cn.pku.eecs.ldn.activity;

import java.util.Currency;

import cn.pku.eecs.ldn.R;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class TestAnimationActivity extends Activity implements OnClickListener{
	private static final String TAG = "TestAnimationActivity";
	ImageView imageView = null;
	AnimationDrawable animationDrawable = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test_animation);
		imageView = (ImageView) findViewById(R.id.imageView);
		imageView.setOnClickListener(this);
//		imageView.setBackgroundResource(R.drawable.drawable_animation);
//		animationDrawable = (AnimationDrawable) imageView.getBackground();
		animationDrawable = (AnimationDrawable) imageView.getDrawable();
	}

	private void runAnimation() {
		Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
		imageView.startAnimation(hyperspaceJumpAnimation);
		hyperspaceJumpAnimation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation arg0) {
				Log.d(TAG, "onAnimationStart");
			}
			
			@Override
			public void onAnimationRepeat(Animation arg0) {
				Log.d(TAG, "onAnimationRepeat");
			}
			
			@Override
			public void onAnimationEnd(Animation arg0) {
				Log.d(TAG, "onAnimationEnd");
			}
		});
	}
	
	@Override
	public void onClick(View v) {
//		runAnimation();
		animationDrawable.stop();
		animationDrawable.start();
	}
}
